<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>王者荣耀原画下载</title>
    <link rel="stylesheet" href="/res/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/global2.css" media="all">
    <script src="/js/jquery.min.js"></script>
    <script src="/js/common.variate.js"></script>
    <script src="/js/common.method.js"></script>
    <style>
        .layui-col-md6 {
            width: 50%;
            padding: 10px;
        }
        .fly-extend-banner-search {
            position: absolute;
            left: 0;
            /*top: 250px;*/
            width: 100%;
            text-align: center;
        }

        .layui-input {
            height: 42px;
            border: none;
            width: 300px;
            box-shadow: 0 0 10px rgba(0,0,0,.15);
            border-radius: 2px 0 0 2px;
        }
        .layui-col-space{
            padding-top: 40px;
        }

        .fly-extend-banner-title {
            /*top: 90px;*/
            font-size: 60px;
            font-weight: 300;
            color: #fff;
            color: rgba(255,255,255,1);
        }
        .fly-extend-list{
            height: 240px;
            background-size:100%;
            background-position: center;
        }
        .layui-card:last-child{
            border-radius: 7px
        }
    </style>
</head>
<body>

<div class="fly-extend-banner">
    <div class="layui-carousel" id="test1" data-height="600px" lay-anim="fade" lay-indicator="inside" lay-arrow="none" style="width: 100%; height: 600px;">
        <div carousel-item id="carousel">
            <div th:each="slideshow : ${slideshows}" th:style="'background-image:url('+${slideshow.cover}+')'">
                <div></div>
            </div>
        </div>
        <div class="layui-carousel-ind">
            <ul>
                <li class="layui-this"></li>
                <li class=""></li>
            </ul>
        </div>
    </div>
    <h1 class="fly-extend-banner-title">王者荣耀原画下载</h1>
    <form class="fly-extend-banner-search">
        <div class="layui-inline">
            <input id="search" placeholder="搜索英雄或皮肤" autocomplete="off" value="" class="layui-input" />
        </div><input value="搜索" onclick="loadData(true)" type="button" class="layui-btn"/>
    </form>
<!--    <div class="fly-extend-banner-release">-->
<!--        <a onclick="beginDownload()" class="layui-btn layui-btn-lg">一键下载</a>-->
<!--    </div>-->
</div>


<div class="layui-container" id="container">
    <ul class="layui-row layui-col-space" id="docs">
    </ul>
    <div id="test2" style="text-align: center;margin-top: 30px;"></div>
</div>

<div class="fly-footer">
    <p> 2018 &copy; <a href="https://gitee.com/chaofan2685_admin" target="_blank">炒饭</a></p>
    <p>
        <a href="tencent://message/?uin=894195915&Site=http://vps.shuidazhe.com&Menu=yes">交个朋友</a>
        <a href=mailto:chaofan2685@qq.com>问题反馈</a>
    </p>
</div>

<script src="/res/layui/layui.all.js"></script>
<script>

    var map = new Map();

    window.onload= function () {
        loadCarousel();
        loadData(false);
    }

    //监听按键
    $(document).keydown(function(e) {
        // 回车键发送消息
        if (e.keyCode == 13) {
            loadData(true);
            return false;
        }
    });

    function loadCarousel() {
        var h = window.innerHeight;
        var formTop = window.innerHeight*4/10;
        var h1Top =  formTop-200;
        var donwTop = formTop+120;
        $(".fly-extend-banner-search").css('top',formTop+'px');
        $(".fly-extend-banner-title").css('top',h1Top+'px');
        $(".fly-extend-banner-release").css('top',donwTop+'px');
        layui.use('carousel', function(){
            var carousel = layui.carousel;
            //建造实例
            carousel.render({
                elem: '#test1'
                ,width: '100%' //设置容器宽度
                ,height: h+"px" //设置容器宽度
                ,arrow: 'none' //始终显示箭头
                ,anim: 'updown' //切换动画方式
                ,interval: 4000 //切换动画方式
            });
        });
    }

    function loadData(jump) {
        var name = $("#search").val();
        map.clear();
        $.ajax({
            type: "GET",
            url: "/api/search",
            data: {name:name},
            dataType: "json",
            success: function(data){
                if (data.code == 8200){
                    $("#docs").html("");
                    var docs = data.data;
                    var index = 0;
                    docs.forEach(function (doc) {
                        index+=1;
                        var html = buildHtml(index+"."+doc.name,doc.cover);
                        $("#docs").append(html);
                        map.set(index+"."+doc.name,doc.list);
                    });
                    if (jump){
                        var h = $("#test1").height();
                        $("html,body").animate({scrollTop:h},500);
                    }
                }else {
                    layer.msg(data.message,{anim: 6});
                }
            }
        });
    }

    function zip() {
        layer.load(3,{shade: 0.6});
        var name = $("#search").val();
        $.ajax({
            type: "GET",
            url: "/api/zip",
            data: {name:name},
            dataType: "json",
            success: function(data){
                if (data.code == 8200){
                    layer.closeAll();
                    location.href = "/api/download?zipPash="+data.data;
                }else {
                    layer.closeAll('loading');
                    layer.msg(data.message,{anim: 6});
                }
            }
        });
    }
    
    function beginDownload() {
        var name = $("#search").val();
        if (!isEmpty(name)){
            layer.open({
                type: 1,
                title: '拖动滑块进行验证(如果下载失败就多试几次)',
                area: ['340px', '290px'], //宽高
                content: html1
            });
        }else {
            layer.msg("请输入英雄或皮肤名称",{anim: 6});
        }
    }

    function details(obj) {
        var html = map.get(obj.title);
        layer.open({
            type: 1
            ,title: '原图展示'
            ,shade: false
            ,area: ['100%', '100%']
            ,scrollbar: false
            ,content: html
        });

    }


</script>
</body>
</html>